{% extends 'layout.html' %}
{% load permission %}
{% load static %}

{% block content %}
    <div class="table">
    
        {% include 'include/search_group.html' %}
    
        <div class="add_btn">
            {% add_permission request 'customer_add' %}

            <div class="right">
                <form class="form-inline" method="get">
                    <div class="form-group">
                        <input name="keyword" type="text" class="form-control" placeholder="请输入关键字"
                               value="{{ keyword }}">
                    </div>
                    <button type="submit" class="btn btn-default">
                        <span class="glyphicon glyphicon-search"></span>
                    </button>
                </form>
            </div>
        </div>

        <table class="table table-bordered">
            <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>手机号</th>
                <th>账户余额</th>
                <th>级别</th>
                <th>创建日期</th>
                <th>交易记录</th>
                <th>重置密码</th>
                {% if request|td_permission:'customer_edit,customer_delete' %}
                    <th>操作</th>
                {% endif %}
            </tr>
            </thead>
            <tbody>
            {% for item in queryset %}
                <tr row-id="{{ item.id }}">
                    <th scope="row">{{ item.id }}</th>
                    <td>{{ item.username }}</td>
                    <td>{{ item.mobile }}</td>
                    <td>{{ item.balance }}</td>
                    <td>{{ item.level.title }}（{{ item.level.percent }}%）</td>
                    <td>{{ item.create_date|date:'Y-m-d' }}</td>
                    <td><a href="{% url 'customer_charge' pk=item.id %}">交易记录</a></td>
                    <td><a href="{% url 'customer_reset' pk=item.id %}">重置密码</a></td>
                    {% if request|td_permission:'customer_edit,customer_delete' %}
                        <td>
                            {% edit_permission request 'customer_edit' pk=item.id %}
                            {% delete_permission request 'customer_delete' cid=item.id %}
                        </td>
                    {% endif %}
                </tr>
            {% endfor %}
            </tbody>
        </table>

        {% include 'include/delete_modal.html' %}

        <nav aria-label="Page navigation">
            <ul class="pagination">
                {{ page_html }}
            </ul>
        </nav>
    </div>
{% endblock %}

{% block js %}
    <script>
        var DELETE_ID;
        var DELETE_URL = "{% url 'customer_delete' %}"
    </script>
    <script src="{% static 'js/delete_modal.js' %}"></script>
{% endblock %}
